import time
import unittest
import random

from selenium import webdriver
from selenium.webdriver.common.by import By
# from unittest import TestCase
from ddt import ddt, data, unpack
from method import method
from _init_ import TestCaseOne

da1 = [
    ['lisi', 123456, "伊朗中央银行", 1234567891548796]
]
da2 = [
    ['lisi', 123456, "伊拉克国民银行", 12345678915487967]
]
da3 = [
    ['lisi', 123456, "伊拉克国民银行", 1234567891548796]
]
da4 = [
    ['lisi', 123456, "伊拉克国民银行", 1234567891548796]
]
da5 = [
    ['lisi', 123456, "伊拉克国民银行", 1234567891548796]
]
da6 = [
    ['lisi', 123456, "伊拉克国民银行", 1234567891548796]
]
da7 = [
    ['lisi', 123456, "中国银行", 1234567891548796, "中国建设银行"]
]
da8 = [
    ['lisi', 123456, "中国银行", 1234567891548796]
]
da9 = [
    ['lisi', 123456, "中国建设银行", 12345678915487967]
]
da10 = [
    ['lisi', 123456, "中国建设银行", 1234567891548796]
]


# 选择跳过的方法
def chooseSkip(get_skip_or_no_skip, get_choose_case):
    all_test = []
    for i in range(1, 11):
        all_test.append(i)
    for j in get_choose_case:
        all_test.remove(j)
    if get_skip_or_no_skip == 1:
        the_choose_skip = all_test
    else:
        the_choose_skip = get_choose_case
    return the_choose_skip


# 选择跳过所选用例则选择0，选择执行所选用例则选择1
skip_or_no_skip = 0
choose_case = []
choose_skip = chooseSkip(skip_or_no_skip, choose_case)

s = method()
# 创建一个列表用来存储选择，有多少方法就准备多少元素
skip_test = s.skipTest(10, choose_skip)


@ddt
class TestBankcard(TestCaseOne):
    @unittest.skipIf(skip_test[0] == 1, "暂时跳过")
    @data(*da1)
    @unpack
    def test_001_addCardSuccess(self, a, b, c, d):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        s.cleanCardByBank(c)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人中心
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-account-location']").click()
        time.sleep(1)

        # 点击银行卡管理
        driver.find_element(By.LINK_TEXT, "银行卡管理").click()
        time.sleep(1)

        # 点击新增
        driver.find_element(By.ID, "bankCard_add_modal_btn").click()
        time.sleep(1)

        # 输入银行名称
        driver.find_element(By.ID, "cardBank_add_input").send_keys(c)
        # time.sleep(1)

        # 选择借记卡
        all_elm = driver.find_elements(By.XPATH, "//label[@class='lyear-radio radio-inline']")
        all_elm[0].click()
        time.sleep(1)

        # 输入16位正常卡号
        driver.find_element(By.ID, "cardNum_add_input").send_keys(d)
        # time.sleep(1)

        # 点击保存
        driver.find_element(By.ID, "bankCard_save_btn").click()
        time.sleep(3)

        #  获取实际标题结果
        #  遍历所有h4标签，获取所有银行卡名称
        result = driver.find_elements(By.TAG_NAME, "h4")
        #  将银行卡名称转化为text格式，重新组成列表
        result_text = []
        for i in range(len(result)):
            t = result[i].text
            result_text.append(t)
        # 从数据库中获取用户所有银行卡
        userid = s.findIdByUserame(a)
        cardnums = s.findBankcardById(userid)
        flag = True
        # 判断银行卡名称是否在列表中
        flag2 = True
        if "伊朗中央银行 (借记卡)" not in result_text and "伊朗中央银行 (借记卡)(默认)" not in result_text:
            flag2 = False
        if flag2 == True and (str(d),) in cardnums:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_001_addCardSuccess")
            driver.save_screenshot(screenshot)
            flag = False

        time.sleep(3)

        self.assertEqual(True, flag)

        driver.close()
        time.sleep(2)

    @unittest.skipIf(skip_test[1] == 1, "暂时跳过")
    @data(*da2)
    @unpack
    def test_002_addCardFailByNumAbnormal(self, a, b, c, d):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        s.cleanCardByNum(d)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人中心
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-account-location']").click()
        time.sleep(1)

        # 点击银行卡管理
        driver.find_element(By.LINK_TEXT, "银行卡管理").click()
        time.sleep(1)

        # 点击新增
        driver.find_element(By.ID, "bankCard_add_modal_btn").click()
        time.sleep(1)

        # 输入银行名称
        driver.find_element(By.ID, "cardBank_add_input").send_keys(c)
        # time.sleep(1)

        # 选择借记卡
        allelm = driver.find_elements(By.XPATH, "//label[@class='lyear-radio radio-inline']")
        allelm[0].click()
        time.sleep(1)

        # 输入17位异常卡号
        driver.find_element(By.ID, "cardNum_add_input").send_keys(d)
        # time.sleep(1)

        # 点击保存
        driver.find_element(By.ID, "bankCard_save_btn").click()
        time.sleep(3)

        #  获取实际标题结果
        # 获取银行卡
        userid = s.findIdByUserame(a)
        cardnums = s.findBankcardById(userid)
        #  print(cardnums)
        flag = True
        # 判断银行卡名称是否在列表中
        if (str(d),) not in cardnums:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_002_addCardFailByNumAbnormal")
            driver.save_screenshot(screenshot)
            flag = False

        time.sleep(3)

        driver.close()

        self.assertEqual(True, flag)

        time.sleep(2)

    @unittest.skipIf(skip_test[2] == 1, "暂时跳过")
    @data(*da3)
    @unpack
    def test_003_addCardFailByNumRepeat(self, a, b, c, d):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        p = len(s.findBankcardByNum(d))
        userid = s.findIdByUserame(a)
        if p == 0:
            s.addCompleteBankcard(c, d, userid, 10000)
        else:
            s.cleanCardByNum(d)
            s.addCompleteBankcard(c, d, userid, 10000)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人中心
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-account-location']").click()
        time.sleep(1)

        # 点击银行卡管理
        driver.find_element(By.LINK_TEXT, "银行卡管理").click()
        time.sleep(1)

        # 点击新增
        driver.find_element(By.ID, "bankCard_add_modal_btn").click()
        time.sleep(1)

        # 输入银行名称
        driver.find_element(By.ID, "cardBank_add_input").send_keys(c)
        # time.sleep(1)

        # 选择借记卡
        allelm = driver.find_elements(By.XPATH, "//label[@class='lyear-radio radio-inline']")
        allelm[0].click()
        time.sleep(1)

        # 输入卡号
        driver.find_element(By.ID, "cardNum_add_input").send_keys(d)
        # time.sleep(1)

        # 点击保存
        driver.find_element(By.ID, "bankCard_save_btn").click()
        time.sleep(3)

        #  获取实际标题结果
        # 获取银行卡
        cardnums = s.findBankcardByNum(d)
        t = len(cardnums)
        # 判断银行卡是否唯一
        if t == 1:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_003_addCardFailByNumRepeat")
            driver.save_screenshot(screenshot)

        time.sleep(3)

        driver.close()

        self.assertEqual(1, t)

        time.sleep(2)

    @unittest.skipIf(skip_test[3] == 1, "暂时跳过")
    @data(*da4)
    @unpack
    def test_004_addCardFailByCardType(self, a, b, c, d):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        p = len(s.findBankcardByNum(d))
        userid = s.findIdByUserame(a)
        if p == 0:
            s.addCompleteBankcard(c, d, userid, 10000)
        else:
            s.cleanCardByNum(d)
            s.addCompleteBankcard(c, d, userid, 10000)
        s.setCardTypeByNum(1, d)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人中心
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-account-location']").click()
        time.sleep(1)

        # 点击银行卡管理
        driver.find_element(By.LINK_TEXT, "银行卡管理").click()
        time.sleep(1)

        # 点击新增
        driver.find_element(By.ID, "bankCard_add_modal_btn").click()
        time.sleep(1)

        # 输入银行名称
        driver.find_element(By.ID, "cardBank_add_input").send_keys(c)
        # time.sleep(1)

        # 选择信用卡
        allelm = driver.find_elements(By.XPATH, "//label[@class='lyear-radio radio-inline']")
        allelm[1].click()
        time.sleep(1)

        # 输入16位卡号
        driver.find_element(By.ID, "cardNum_add_input").send_keys(d)
        # time.sleep(1)

        # 点击保存
        driver.find_element(By.ID, "bankCard_save_btn").click()
        time.sleep(3)

        #  获取实际标题结果
        # 获取银行卡
        cardnums = s.findBankcardByNum(d)
        t = len(cardnums)
        # 判断银行卡是否唯一
        if t == 1:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_004_addCardFailByCardType")
            driver.save_screenshot(screenshot)

        time.sleep(3)
        driver.close()

        self.assertEqual(1, t)

        time.sleep(2)

    @unittest.skipIf(skip_test[4] == 1, "暂时跳过")
    @data(*da5)
    @unpack
    def test_005_deleteCardSuccess(self, a, b, c, d):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        userid = s.findIdByUserame(a)
        # 随机生成1到5张银行卡
        r = random.randint(1, 5)
        for k in range(r):
            n = s.generateNum(k + d + 1)
            s.cleanCardByNum(n)
            s.addCompleteBankcard(c, n, userid, 10000)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人中心
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-account-location']").click()
        time.sleep(1)

        # 点击银行卡管理
        driver.find_element(By.LINK_TEXT, "银行卡管理").click()
        time.sleep(1)

        # 点击删除
        # 获取所有银行卡删除按钮
        buttons = driver.find_elements(By.XPATH, "//button[@class='btn btn-danger delete_btn']")
        t = len(buttons)
        time.sleep(1)

        # 随机选取一张卡
        ran = random.randint(0, (t - 1))
        button = buttons[ran]

        # 保存删除银行卡信息(功能未实现，不能自动恢复删除银行卡)
        # 获取所有银行卡卡号
        nums1 = driver.find_elements(By.XPATH, "//div[@class='card-body']/h4")
        nums2 = []
        for i in nums1:
            l = i.text
            if "卡号" in l:
                nums2.append(l)
        # 获取删除银行卡号
        num = nums2[ran][3:]
        # print("删除银行卡信息为：", s.findBankcardByNum(num))

        # 点击删除
        button.click()
        time.sleep(1)

        # 点击确认删除
        # print(len(driver.find_elements(By.XPATH, "//div[@class='jconfirm-buttons']")))
        driver.find_element(By.XPATH, "//div[@class='jconfirm-buttons']/button").click()
        time.sleep(3)
        #  获取实际结果
        flag = True
        # 获取银行卡
        cardnums = s.findBankcardById(userid)
        # 判断银行卡名称是否在列表中
        # 需要改进————删除银行卡后，删除成功提示框很快消失，找不到对应元素
        if (str(num),) not in cardnums:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_005_deleteCardSuccess")
            driver.save_screenshot(screenshot)
            flag = False
        time.sleep(3)

        driver.close()

        self.assertEqual(True, flag)

        time.sleep(2)

    @unittest.skipIf(skip_test[5] == 1, "暂时跳过")
    @data(*da6)
    @unpack
    def test_006_deleteCardFail(self, a, b, c, d):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        userid = s.findIdByUserame(a)
        # 随机生成1到5张银行卡
        r = random.randint(1, 5)
        for k in range(r):
            n = s.generateNum(k + d + 1)
            s.cleanCardByNum(n)
            s.addCompleteBankcard(c, n, userid, 10000)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人中心
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-account-location']").click()
        time.sleep(1)

        # 点击银行卡管理
        driver.find_element(By.LINK_TEXT, "银行卡管理").click()
        time.sleep(1)

        # 点击删除
        # 获取所有银行卡删除按钮
        buttons = driver.find_elements(By.XPATH, "//button[@class='btn btn-danger delete_btn']")
        t = len(buttons)
        time.sleep(1)

        # 随机选取一张卡
        ran = random.randint(0, (t - 1))
        button = buttons[ran]

        # 保存删除银行卡信息(功能未实现，不能自动恢复删除银行卡)
        # 获取所有银行卡卡号
        nums1 = driver.find_elements(By.XPATH, "//div[@class='card-body']/h4")
        nums2 = []
        for i in nums1:
            l = i.text
            if "卡号" in l:
                nums2.append(l)
        # 获取删除银行卡号
        num = nums2[ran][3:]
        # print("删除银行卡信息为：", s.findBankcardByNum(num))

        # 点击删除
        button.click()
        time.sleep(1)

        # 点击取消
        # print(len(driver.find_elements(By.XPATH, "//div[@class='jconfirm-buttons']")))
        dorq = driver.find_elements(By.XPATH, "//div[@class='jconfirm-buttons']/button")
        dorq[1].click()
        time.sleep(3)
        #  获取实际标题结果
        flag = True
        # 获取银行卡
        cardnums = s.findBankcardById(userid)
        # 判断银行卡名称是否在列表中
        if (str(num),) in cardnums:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_006_deleteCardFail")
            driver.save_screenshot(screenshot)
            flag = False

        time.sleep(3)

        driver.close()

        self.assertEqual(flag, True)

        time.sleep(2)

    @unittest.skipIf(skip_test[6] == 1, "暂时跳过")
    @data(*da7)
    @unpack
    def test_007_upDataBankName(self, a, b, c, d, e):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        userid = s.findIdByUserame(a)
        # 随机生成1到5张银行卡
        r = random.randint(1, 5)
        for k in range(r):
            n = s.generateNum(k + d + 1)
            s.cleanCardByNum(n)
            s.addCompleteBankcard(e, n, userid, 10000)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人中心
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-account-location']").click()
        time.sleep(1)

        # 点击银行卡管理
        driver.find_element(By.LINK_TEXT, "银行卡管理").click()
        time.sleep(1)

        # 点击编辑
        # 获取所有银行卡删除按钮
        buttons = driver.find_elements(By.XPATH, "//button[@class='btn btn-primary update_btn']")
        t = len(buttons)
        time.sleep(1)

        # 随机选取一张卡
        ran = random.randint(0, (t - 1))
        button = buttons[ran]

        # 保存修改银行卡信息(功能未实现，不能自动恢复修改的银行卡)
        # 获取所有银行卡卡号
        nums1 = driver.find_elements(By.XPATH, "//div[@class='card-body']/h4")
        nums2 = []
        for i in nums1:
            l = i.text
            if "卡号" in l:
                nums2.append(l)
        # 获取删除银行卡号
        num = nums2[ran][3:]
        old_data = s.findBankcardByNum(num)

        # 点击编辑
        button.click()
        time.sleep(1)

        # 输入银行名称
        bankname = driver.find_element(By.ID, "cardBank_update_input")
        bankname.clear()
        bankname.send_keys(c)
        time.sleep(1)
        '''
        # 选择借记卡
        allelm = driver.find_elements(By.XPATH, "//label[@class='lyear-radio radio-inline']")
        if s.findCartypeByNum(num) == 1:
            allelm[0].click()
        else:
            allelm[1].click()
        time.sleep(1)

        # 输入16位正常卡号
        driver.find_element(By.ID, "cardNum_add_input").send_keys(d)
        # time.sleep(1)
        '''
        # 点击更新
        driver.find_element(By.ID, "bankCard_update_btn").click()
        time.sleep(3)

        #  获取实际标题结果
        # 获取银行卡
        new_data = s.findBankcardByNum(num)
        # 判断新银行卡信息是否等于旧信息
        # 获取不到修改失败元素
        if new_data == old_data:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_007_upDataBankName")
            driver.save_screenshot(screenshot)
        time.sleep(3)

        driver.close()

        self.assertEqual(old_data, new_data)

        time.sleep(2)

    @unittest.skipIf(skip_test[7] == 1, "暂时跳过")
    @data(*da8)
    @unpack
    def test_008_upDataCardNum(self, a, b, c, d):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        userid = s.findIdByUserame(a)
        # 随机生成1到5张银行卡
        r = random.randint(1, 5)
        for k in range(r):
            n = s.generateNum(k + d + 1)
            s.cleanCardByNum(n)
            s.addCompleteBankcard(c, n, userid, 10000)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人中心
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-account-location']").click()
        time.sleep(1)

        # 点击银行卡管理
        driver.find_element(By.LINK_TEXT, "银行卡管理").click()
        time.sleep(1)

        # 点击编辑
        # 获取所有银行卡删除按钮
        buttons = driver.find_elements(By.XPATH, "//button[@class='btn btn-primary update_btn']")
        t = len(buttons)
        time.sleep(1)

        # 随机选取一张卡
        ran = random.randint(0, (t - 1))
        button = buttons[ran]

        # 保存修改银行卡信息(功能未实现，不能自动恢复修改的银行卡)
        # 获取所有银行卡卡号
        nums1 = driver.find_elements(By.XPATH, "//div[@class='card-body']/h4")
        nums2 = []
        for i in nums1:
            l = i.text
            if "卡号" in l:
                nums2.append(l)
        # 获取修改银行卡号
        old_num = nums2[ran][3:]
        the_id = s.findCardidByNum(old_num)

        # 点击编辑
        button.click()
        time.sleep(1)
        '''
        # 输入银行名称
        driver.find_element(By.ID, "cardBank_update_input").send_keys(c)
        time.sleep(1)
        
        # 选择借记卡
        allelm = driver.find_elements(By.XPATH, "//label[@class='lyear-radio radio-inline']")
        if s.findCartypeByNum(num) == 1:
            allelm[0].click()
        else:
            allelm[1].click()
        time.sleep(1)
        '''
        # 输入16位正常卡号
        updata_num = d
        while True:
            if str(updata_num) != old_num:
                break
            else:
                n = d + 1
                updata_num = s.generateNum(n)
        input_num = driver.find_element(By.ID, "cardNum_update_input")
        input_num.clear()
        input_num.send_keys(updata_num)
        time.sleep(1)

        # 点击更新
        driver.find_element(By.ID, "bankCard_update_btn").click()
        time.sleep(3)

        #  获取实际标题结果
        # 获取银行卡
        new_num = s.findCardnumByCardid(the_id)
        # 判断银行卡名称是否在列表中
        # 需要修改————判断是否有修改成功
        if old_num != new_num:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_008_upDataCardNum")
            driver.save_screenshot(screenshot)
        time.sleep(3)
        driver.close()

        self.assertNotEqual(old_num, new_num)

        time.sleep(2)

    @unittest.skipIf(skip_test[8] == 1, "暂时跳过")
    @data(*da9)
    @unpack
    def test_009_upDataCardNumAbnormal(self, a, b, c, d):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        userid = s.findIdByUserame(a)
        # 随机生成1到5张银行卡
        r = random.randint(1, 5)
        for k in range(r):
            n = s.generateNum(k + d + 1)
            s.cleanCardByNum(n)
            s.addCompleteBankcard(c, n, userid, 10000)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人中心
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-account-location']").click()
        time.sleep(1)

        # 点击银行卡管理
        driver.find_element(By.LINK_TEXT, "银行卡管理").click()
        time.sleep(1)

        # 点击编辑
        # 获取所有银行卡删除按钮
        buttons = driver.find_elements(By.XPATH, "//button[@class='btn btn-primary update_btn']")
        t = len(buttons)
        time.sleep(1)

        # 随机选取一张卡
        ran = random.randint(0, (t - 1))
        button = buttons[ran]

        # 点击编辑
        button.click()
        time.sleep(1)
        '''
        # 输入银行名称
        driver.find_element(By.ID, "cardBank_update_input").send_keys(c)
        time.sleep(1)
    
        # 选择借记卡
        allelm = driver.find_elements(By.XPATH, "//label[@class='lyear-radio radio-inline']")
        if s.findCartypeByNum(num) == 1:
            allelm[0].click()
        else:
            allelm[1].click()
        time.sleep(1)
        '''
        # 输入17位异常卡号
        updata_num = d
        input_num = driver.find_element(By.ID, "cardNum_update_input")
        input_num.clear()
        input_num.send_keys(updata_num)
        time.sleep(1)

        # 点击更新
        driver.find_element(By.ID, "bankCard_update_btn").click()
        time.sleep(3)

        #  获取实际标题结果
        elms = driver.find_elements(By.XPATH, "//span[@class='help-block']")
        result = elms[3].text

        # 判断是否出现不合法报错
        if result == "银行卡号不合法":
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_009_upDataCardNumAbnormal")
            driver.save_screenshot(screenshot)
        time.sleep(3)
        driver.close()

        self.assertEqual("银行卡号不合法", result)

        time.sleep(2)

    @unittest.skipIf(skip_test[9] == 1, "暂时跳过")
    @data(*da10)
    @unpack
    def test_010_upDataCardType(self, a, b, c, d):
        # 清理数据库，准备测试数据
        t = s.findUsername(a)
        if len(t) != 0:
            s.cleanDatabaseByUsername(a)
            s.addUsername(a)
        else:
            s.addUsername(a)
        userid = s.findIdByUserame(a)
        # 随机生成1到5张银行卡
        r = random.randint(1, 5)
        for k in range(r):
            n = s.generateNum(k + d + 1)
            s.cleanCardByNum(n)
            s.addCompleteBankcard(c, n, userid, 10000)
        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 正常登录
        # 输入用户名
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(a)

        #  输入密码
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(b)

        # 点击登陆
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()
        time.sleep(1)

        # 点击个人中心
        driver.find_element(By.XPATH, "//i[@class='mdi mdi-account-location']").click()
        time.sleep(1)

        # 点击银行卡管理
        driver.find_element(By.LINK_TEXT, "银行卡管理").click()
        time.sleep(1)

        # 点击编辑
        # 获取所有银行卡删除按钮
        buttons = driver.find_elements(By.XPATH, "//button[@class='btn btn-primary update_btn']")
        t = len(buttons)
        time.sleep(1)

        # 随机选取一张卡
        ran = random.randint(0, (t - 1))
        button = buttons[ran]

        # 保存修改银行卡信息(功能未实现，不能自动恢复修改的银行卡)
        # 获取所有银行卡卡号
        nums1 = driver.find_elements(By.XPATH, "//div[@class='card-body']/h4")
        nums2 = []
        for i in nums1:
            l = i.text
            if "卡号" in l:
                nums2.append(l)
        # 获取修改银行卡号
        old_num = nums2[ran][3:]
        # 获取旧的银行卡信息
        old_type = s.findCartypeByNum(old_num)

        # 点击编辑
        button.click()
        time.sleep(3)
        '''
        # 输入银行名称
        driver.find_element(By.ID, "cardBank_update_input").send_keys(c)
        time.sleep(1)
        '''
        # 选择借记卡
        allelm = driver.find_elements(By.XPATH, "//label[@class='lyear-radio radio-inline']")
        o = s.findCartypeByNum(old_num)
        if o == ((1,),):
            allelm[3].click()
        else:
            allelm[2].click()
        time.sleep(1)
        '''
        # 输入17位异常卡号
        updata_num = d
        input_num = driver.find_element(By.ID, "cardNum_update_input")
        input_num.clear()
        input_num.send_keys(updata_num)
        time.sleep(1)
        '''
        # 点击更新
        driver.find_element(By.ID, "bankCard_update_btn").click()
        time.sleep(3)

        #  获取实际标题结果
        new_type = s.findCartypeByNum(old_num)
        # 判断是否出现不合法报错
        if old_type != new_type:
            print("用例通过！")
        else:
            print("用例不通过！")
            screenshot = s.failedScreenshotNamed("test_010_upDataCardType")
            driver.save_screenshot(screenshot)
        time.sleep(3)
        driver.close()

        self.assertNotEqual(old_type, new_type)

        time.sleep(2)
